<?php

class letFunction
{
    /**
     *
     * @param type $where
     * @param type $string
     * @return string Add WHERE for sql
     */
	public static function addWhere($where = '', $string = '')
	{
        if (!isset ($where) OR $where == NULL OR $where == '')
            $where = $string;
        else
            $where .= ' AND ' . $string;
        return $where;
	}

    /**
     *
     * @param type $status
     * @return type 
     */
	public static function statusToImages($status = NULL)
	{
        if ($status == 1)
            $result = '<img src="'.Yii::app()->theme->baseUrl.'/common/img/icon/icon_check_16.png" />';
        elseif ($status == 0)
            $result = '<img src="'.Yii::app()->theme->baseUrl.'/common/img/icon/icon_disable_16.png" />';
        else
            $result = '';
        return $result;
	}
    
    public static function statusLink($model, $column, $id, $status) {
        $value = ($status) ? 0 : 1;
        $params = "model=$model&id=$id&column=$column&value=$value"; 
        echo CHtml::link(letFunction::statusToImages($status), "", array(
            'id'=>$column.'_'.$id,
            'onclick'=>'loadAjaxReturnParent("'.Yii::app()->createUrl('//global/ChangeStatusValue/index').'", "'.$params.'", "'.$column.'_'.$id.'")'
        ));
    }

}